//
// Created by francklinson on 2022/3/1 AT 22:37.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows < 2) {
            return s;
        }
        unsigned int n = s.length();
        vector<string> res = vector<string>(numRows);
        int i = 0;
        int flag = -1;
        for (auto &x:s) {
            res[i] += x;
            if (i == 0 || i == numRows - 1) {
                flag *= -1;
            }
            i += flag;
        }
        string ans;
        for (auto &x:res) {
            ans += x;
        }
        return ans;
    }
};

int main() {
    Solution solution;
    cout << solution.convert("PAYPALISHIRING", 4) << endl;
    return 0;
}

